Title: SQL BT (By-BKK) / 06 Joins
Tags: Obsidian_to_Anki

Q: What is database normalization in SQL?
A: The process of organizing data into separate tables to minimize duplication

Q: True or False: Distributed data across multiple tables increases query complexity.
A: True

Q: What is a primary key used for in multi-table databases?
A: Uniquely identifies rows across tables

Q: What SQL clause joins tables using a primary key or common column?
A: JOIN or INNER JOIN

Q: How does INNER JOIN work in SQL?
A: Combines rows from two tables if their keys match

Q: What does the ON keyword specify in an INNER JOIN?
A: The condition that links the tables, usually by matching keys

Q: Reverse card: JOIN or INNER JOIN
A: Which clause combines rows from two tables based on matching keys?

Q: Reverse card: True
A: Does database normalization make queries a bit more complex?

Q: Reverse card: Uniquely identifies rows across tables
A: What does a primary key do in a multi-table SQL database?

Q: Write the basic form of an INNER JOIN query in SQL.
A: SELECT columns FROM table1 INNER JOIN table2 ON table1.id = table2.id WHERE conditions

Q: True or False: JOIN and INNER JOIN mean the same in SQL.
A: True

Q: What is a common type of primary key in database tables?
A: Auto-incrementing integer

Q: Reverse card: Auto-incrementing integer
A: What is a common type of primary key in SQL tables?

Q: Write a query to list domestic and international sales for each movie.
A: SELECT title, domestic_sales, international_sales FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id

Q: How would you show movies with more international sales than domestic sales?
A: SELECT title FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id WHERE international_sales > domestic_sales

Q: How do you list movies by their ratings in descending order?
A: SELECT title, rating FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id ORDER BY rating DESC

Q: Reverse card: SELECT title, rating FROM movies INNER JOIN boxoffice ON movies.id = boxoffice.movie_id ORDER BY rating DESC
A: How do you get the list of movies ordered by rating from highest to lowest?